//
//  main.cpp
//  syncer_1_1
//
//  Created by Silvtar on 11/27/12.
//  Copyright (c) 2012 Silvtar. All rights reserved.
//

//
//  main.cpp
//  NetTransferClient
//
//  Created by Silvtar on 11/19/12.
//  Copyright (c) 2012 Silvtar. All rights reserved.
//
#include	<sys/types.h>
#include 	<sys/socket.h>
#include	<netinet/in.h>
#include  	<arpa/inet.h>
#include	<unistd.h>
#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#include	<string>
#include	"netio.c"
#include	"FileTree.h"

const std::string loDir = "/home/silvtar/Ubuntu One";

int main(int argc, const char * argv[]) {

	int sockfd;
	struct sockaddr_in servaddr;

	//建立套接字
	if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		printf("socket error\n");
		return 1;
	}

	//填写地址结构
	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(2012);
	inet_pton(AF_INET, "127.0.0.1", (sockaddr *) &servaddr.sin_addr);	//转换IP地址

	//连接
	if (connect(sockfd, (sockaddr *) &servaddr, sizeof(servaddr)) < 0) {
		printf("ERROR: connect server false\n");
		return 1;
	}

	char ptr[4096] = "";
//	ssize_t size = 0;
	readn(sockfd, ptr, 4096);
	printf("server:%s\n", ptr);

//	SSTree loTree;
//	loTree.build(loDir);

//	printf("loTree's space:%ld \n",sizeof(loTree));

	/*
	bzero(ptr, 4096);
	bcopy(&loTree, ptr, sizeof(loTree));
	writen(sockfd, ptr, 4096);
	*/

	sprintf(ptr, "this is client\n");
	writen(sockfd, ptr, 4096);

	return 0;
}

